package iit.projects.etaxi.view.bean;


import java.util.List;

import javax.faces.event.ActionEvent;

import iit.projects.etaxi.model.dto.DriverSCDO;
import iit.projects.etaxi.model.entity.Driver;
import iit.projects.etaxi.model.service.DriverService;
import iit.projects.etaxi.model.service.ServiceLocator;
import iit.projects.etaxi.util.JSFUtils;

import com.icesoft.faces.component.ext.HtmlInputText;

public class ViewDriversBackingBean {
	
	private Driver driver;
	private List<Driver> drivers;
	
	private HtmlInputText compCode;
	private HtmlInputText compName;
	private HtmlInputText compContactNumber;
	
	private ServiceLocator serviceLocator;
	private DriverService driverService;
	
	public ViewDriversBackingBean() {
	}
	
	@javax.annotation.PostConstruct
	public void init(){
		driverService = serviceLocator.getDriverService();
		this.driver = new Driver();
	}

	public void searchDrivers(ActionEvent event){
		
		DriverSCDO driverSCDO = new DriverSCDO();
		driverSCDO.setName(this.driver.getName());
		driverSCDO.setCode(this.driver.getCode());
		driverSCDO.setContactNumber(this.driver.getContactNumber());
		
		this.drivers = driverService.findDrivers(driverSCDO);
		if(this.drivers == null || this.drivers.isEmpty()){
			JSFUtils.addFacesInfoMessage("data.notfound");
			return;
		}
	}
	
	public void clear(ActionEvent event){
		this.driver = new Driver();
		compName.resetValue();
		compCode.resetValue();
		compContactNumber.resetValue();
	}
	
	public Driver getDriver() {
		return driver;
	}

	public void setDriver(Driver driver) {
		this.driver = driver;
	}

	public List<Driver> getDrivers() {
		return drivers;
	}

	public void setDrivers(List<Driver> drivers) {
		this.drivers = drivers;
	}

	public HtmlInputText getCompCode() {
		return compCode;
	}

	public void setCompCode(HtmlInputText compCode) {
		this.compCode = compCode;
	}

	public HtmlInputText getCompName() {
		return compName;
	}

	public void setCompName(HtmlInputText compName) {
		this.compName = compName;
	}

	public HtmlInputText getCompContactNumber() {
		return compContactNumber;
	}

	public void setcompContactNumber(HtmlInputText compContactNumber) {
		this.compContactNumber = compContactNumber;
	}

	public void setServiceLocator(ServiceLocator serviceLocator) {
		this.serviceLocator = serviceLocator;
	}
}
